<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<script>
		// 1、对象的超类
		console.log("-------1 对象的超类-------")
		var parent = {
			name:"parent",
			foo(){
				console.log("my name is parent")
			}
		}
		let child = {
			name:"child",
			foo(){
				super.foo();
				console.log("my name is child")
			}
		}
		Object.setPrototypeOf(child, parent);
		child.foo()



		// 2、e5中的类
		console.log("-------2 e5中的类------")
		function person(name){
			// 私有属性
			var pravite = {
				color:"red",
				number:1
			}
			this.name = name || "default name";
			this.run = function (run = "default run1"){
				return console.log(this.name+"---"+run);
			}
			// 访问器
			Object.defineProperties(this,{
				color:{
					get(){
						return pravite.color
					},
					set(value){
						pravite.color = value;
						return "pravite.color modified"
					}
				},
				number:{
					get(){
						return pravite.number
					},
					set(value){
						pravite.number = value;
						return "pravite.number modified"
					}

				}
			})




		}
		person.prototype.sex = "男";
		person.prototype.work = function(work = "default work1"){
			console.log(this.name+"---"+this.sex + "---" + work)
		}
		//static function
		person.study = function(study){
			var study = study || "default study"
			return console.log(this.name+"---"+this.sex + "---" + study)
		}
		let people = new person("zhangsan");
		people.run()
		people.run("跑步")
		people.work("写策划")
		// people.study()
		person.study("学数学")//static function
		 people.color= "yellow";
		 people.number = 99;
		console.log("私有属性：", people.color,people.number)



		// es5类的继承
		console.log("--------es5类的继承---------")

		// 对象冒充继承
		console.log("--------对象冒充继承---------")
		function childPerson (name,sno) {
			person.call(this,name)
			this.sno = sno || "default sno";
			this.hobby = function(hobby){
				console.log(this.name+"---"+this.sno+"----"+hobby)
			}
		}
		var people2 = new childPerson ("继承小玲",17102002);
		people2.run("run122222")
		// people2.work("work22222")//无法继承原型链上的方法
		people2.hobby("织毛衣")

		// 原型链继承   无法传参
		console.log("--------原型链继承---------")
		function childPerson2(){
			this.play=function(play){
				console.log(this.name+"---"+play)
			}
		}
		childPerson2.prototype = new person()
		people3 = new childPerson2();
		people3.run();
		people3.play("打篮球");

		// 混合继承
		console.log("--------混合继承---------")
		function childPerson3(name){
			person.apply(this,[name])
		}
		childPerson3.prototype = new person()
		people4 = new childPerson3("lihuaming")
		people4.run()
		people4.work()

		// 3、实现一个new的过程
		function  parentClass (){
			this.name= "小花",
			this.know = function(){
				console.log("===parent know fn===="+this.name)
			}

		}
		// var childClass = new parentClass()
		// childClass.know()

		function newFn(fn){
			var obj = {};
			fn.apply(obj,arguments);
			return obj
		}
		newFn(parentClass).know()









	</script>
	
</body>
</html>